package com.k2091.washcar.controller;


import com.k2091.washcar.entity.FormInline;
import com.k2091.washcar.entity.Users;
import com.k2091.washcar.entity.UsersCar;
import com.k2091.washcar.service.IUsersCarService;
import com.k2091.washcar.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2021-06-02
 */
@RestController
@RequestMapping("/api/car")
public class UsersCarController {

    @Autowired
    private IUsersService usersService;

    @Autowired
    private IUsersCarService carService;

    @RequestMapping("/getCarList")
    @ResponseBody
    public List<UsersCar> getCarList(FormInline formInline){
        List<UsersCar> usersCarList = carService.selectCar(formInline);
        for (UsersCar car: usersCarList) {
            Long id = car.getUserId();
            Users users = usersService.selectUsersById(id);
            if (users!=null) {
                car.setMobile(users.getMobile());
                car.setUserName(users.getName());
            }
        }
        return usersCarList;
    }

    @RequestMapping("/deleteCar")
    public void deldteCar(Long id){
        carService.deleteCar(id);
    }

    @RequestMapping(value = "/upStatus",method = RequestMethod.GET)
    @ResponseBody
    public void upStatus(Long id,int status,String token){
        carService.upStatus(id, status);
    }

    @RequestMapping("/upUsersCar")
    @ResponseBody
    public void upCar(UsersCar car){
        carService.upCar(car);
    }
}
